package com.sxyc.tintin.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Model;

public class WxUser extends Model<WxUser> {
	
	public static final WxUser dao = new WxUser();
	
	// 使用jFinal 日志
	private com.jfinal.log.Log log = com.jfinal.log.Log.getLog(this.getClass());

	public WxUser getWxUser(String openId){
		return WxUser.dao.findFirst("select * from Wx_User where openId = ? and status = 1 ", new Object[] { openId });
	}
	
	public WxUser getWxUserByDeviceId(long deviceId){
		return WxUser.dao.findFirst("select * from Wx_User where deviceId = ? and status = 1 ", new Object[] { deviceId });
	}
	
	public List<WxUser> getAllWxUser(){
		return WxUser.dao.find("select * from Wx_User where 1=1 and status = 1 ", new Object[] {});
	}
	
	public Long getDeviceIdByOpenId(String openId){
		Long deviceId = null;
		try {
			WxUser user = getWxUser(openId);
			if(user!=null){
				deviceId = user.getLong("DeviceId");
			}
		} catch (Exception e) {
			log.error("getDeviceIdByOpenId Exception："+e.getMessage());
		}
		return deviceId;
	} 
	
}
